<template>
  <div>
    <div>
      <el-row style="margin: 10px" :gutter="1">
        <el-col :span="4">
          <el-input
            v-model="selectFrom.projectName"
            placeholder="请输入项目名称"
          >
            <template #prefix>
              <el-icon class="el-input__icon"><search /></el-icon>
            </template>
          </el-input>
        </el-col>
        <el-col span="1">
          <el-button type="primary" @click="this.getProInfo(this.pageNum)"
            >搜索</el-button
          >
        </el-col>
        <el-col span="1">
          <AddProject />
        </el-col>
        <el-col span="3" :push="15">
          <el-button round @click="searchCollapseShowFun()"
            ><el-icon><search /></el-icon>高级检索</el-button
          >
        </el-col>
      </el-row>
    </div>

    <!-- 高级检索 -->
    <div>
      <!-- 折叠面板 -->
      <el-collapse class="searchHead" v-model="showSearch">
        <el-collapse-item name="search">
          <template #title
            ><el-icon size="15px"><Search /></el-icon
            >&nbsp;&nbsp;&nbsp;高级检索</template
          >

          <!-- 表单数据排版 -->
          <el-form ref="selectFrom">
            <!-- 第一行 -->
            <el-row :gutter="56">
              <el-col :offset="2" :span="4"
                ><el-form-item label="项目编号"
                  ><el-input v-model="selectFrom.projectNum" /></el-form-item
              ></el-col>
              <el-col :span="4"
                ><el-form-item label="项目名称"
                  ><el-input v-model="selectFrom.projectName" /></el-form-item
              ></el-col>
              <el-col :span="4"
                ><el-form-item label="主持人&nbsp;&nbsp;&nbsp;"
                  ><el-input v-model="selectFrom.hostname" /></el-form-item
              ></el-col>
              <el-col :span="4"
                ><el-form-item label="本人排名"
                  ><el-input v-model="selectFrom.ranking" /></el-form-item
              ></el-col>
              <el-col :span="4"
                ><el-form-item label="主持单位"
                  ><el-input v-model="selectFrom.hostUnit" /></el-form-item
              ></el-col>
            </el-row>

            <!-- 第二行 -->
            <el-row :gutter="56">
              <el-col :span="4" :offset="2">
                <el-form-item label="合作单位">
                  <el-input v-model="selectFrom.cooperationUnit" />
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="项目级别">
                  <el-select
                    v-model="selectFrom.level"
                    placeholder="项目级别"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in level"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="项目类别">
                  <el-select
                    v-model="selectFrom.classification"
                    placeholder="项目类别"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in classic"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="项目类型">
                  <el-select
                    v-model="selectFrom.projectType"
                    placeholder="项目类型"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in projectType"
                      :key="item.id"
                      :label="item.typeName"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

              <el-col :span="4">
                <el-form-item label="是否结项">
                  <el-select
                    placeholder="是否结项"
                    v-model="selectFrom.endProject"
                  >
                    <el-option label="是" value="1" />
                    <el-option label="否" value="2" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 第三行 -->
            <el-row>
              <el-col :offset="2" :span="9">
                <el-form-item label="起止时间">
                  <template style="display: flex">
                    <el-date-picker
                      placeholder="开始时间"
                      style="width: 150px"
                      v-model="selectFrom.beginDate"
                    />
                    <span>&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&nbsp;</span>
                    <el-date-picker
                      placeholder="结项时间"
                      style="width: 150px"
                      v-model="selectFrom.endDate"
                    />
                  </template>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-button @click="this.getProInfo(this.pageNum)">查询</el-button>
              <el-button
                @click="
                  this.selectFrom = {};
                  this.getProInfo(1);
                "
                >清空</el-button
              >
            </el-row>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>

    <el-table
      :data="tableData"
      style="width: 100%"
      border="true"
      max-height="65vh"
      height="65vh"
      v-loading="loading"
      element-loading-text="Loading..."
      :default-sort="{ prop: 'beginDate', order: 'descending' }"
    >
      <template #empty>
        <el-empty description="未查询到数据"></el-empty>
      </template>
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="50px"
      ></el-table-column>
      <el-table-column
        prop="projectNum"
        label="项目编号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="projectName"
        label="项目名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="hostname"
        label="主持人"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="beginDate"
        label="起始时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="endDate"
        label="结项时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="projectTypeStr"
        label="项目类型"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="levelStr"
        label="项目级别"
        align="center"
      ></el-table-column>
      <el-table-column label="是否结项" align="center">
        <template #default="scope">
          <template v-if="scope.row.endProject === 1">是</template>
          <template v-else>否</template>
        </template>
      </el-table-column>

      <el-table-column prop="" label="操作" align="center" width="250">
        <template #default="scope">
          <el-button-group>
            <el-button
              type="primary"
              @click="detailInfo(scope.row.id)"
              :disabled="!this.hasAuth('sys:project:detail')"
              >详情</el-button
            >
            <el-button
              type="primary"
              @click="updata(scope.row.id)"
              :disabled="
                !this.hasAuth('sys:project:detail') ||
                !this.hasAuth('sys:project:update')
              "
              >修改</el-button
            >
            <el-button
              type="danger"
              @click="delectInfo(scope.row.id)"
              :disabled="!this.hasAuth('sys:project:delete')"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-model:currentPage="currentPage"
      :page-size="10"
      background="true"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @current-change="handleCurrentChange"
    >
    </el-pagination>

    <!-- 详情 -->
    <el-dialog v-model="dialogTableVisible" top="5vh">
      <el-scrollbar height="700px">
        <el-descriptions direction="horizontal" :column="1" border>
          <el-descriptions-item label="项目编号">{{
            detailData.projectNum
          }}</el-descriptions-item>
          <el-descriptions-item label="项目名称">{{
            detailData.projectName
          }}</el-descriptions-item>
          <el-descriptions-item label="主持人">{{
            detailData.hostname
          }}</el-descriptions-item>
          <el-descriptions-item label="团队成员">{{
            detailData.member
          }}</el-descriptions-item>
          <el-descriptions-item label="本人排名">{{
            detailData.ranking
          }}</el-descriptions-item>
          <el-descriptions-item label="主持单位">{{
            detailData.hostUnit
          }}</el-descriptions-item>
          <el-descriptions-item label="起始时间">{{
            detailData.beginDate
          }}</el-descriptions-item>
          <el-descriptions-item label="结项时间">{{
            detailData.endDate
          }}</el-descriptions-item>

          <el-descriptions-item label="项目总金额">{{
            detailData.totalPrice
          }}</el-descriptions-item>

          <el-descriptions-item label="项目类别">{{
            detailData.projectTypeStr
          }}</el-descriptions-item>
          <template v-if="detailData.projectTypeStr === '纵向课题'">
            <el-descriptions-item label="合作单位">{{
              detailData.cooperationUnit
            }}</el-descriptions-item>
            <el-descriptions-item label="项目级别">{{
              detailData.levelStr
            }}</el-descriptions-item>
            <el-descriptions-item label="项目类别">{{
              detailData.classificationStr
            }}</el-descriptions-item>
            <el-descriptions-item label="财政支持金额">{{
              detailData.financePrice
            }}</el-descriptions-item>
            <el-descriptions-item label="自筹金额">{{
              detailData.selfPrice
            }}</el-descriptions-item>
          </template>

          <el-descriptions-item label="剩余金额">
            <router-link :to="{path: '/finance/financeIndex', query: { projectId:detailData.id}}">
              {{ detailData.remainPrice }}
            </router-link>
          </el-descriptions-item>
          <el-descriptions-item label="是否结项">
            <span v-if="detailData.endProject === 1">是</span>
            <span v-else>否</span>
          </el-descriptions-item>

          <el-descriptions-item
            label="技术指标"
            v-if="
              detailData.specifications != null &&
              detailData.specifications != ''
            "
          >
            <show-html v-model="detailData.specifications" />
          </el-descriptions-item>
          <el-descriptions-item label="附件" v-if="detailData.files.length > 0">
            <template v-for="data in detailData.files" :key="data.id">
              <a
                :href="
                  'http://101.43.150.171:8082/PaperInfos/downLoad?fileName=' +
                  data.utilName +
                  '&fileNameSrc=' +
                  data.utilSrcName +
                  '&parameter=' +
                  token
                "
                >{{ data.utilSrcName }}</a
              >
              <br />
            </template>
          </el-descriptions-item>
        </el-descriptions>
      </el-scrollbar>
    </el-dialog>

    <!-- 修改 -->
    <el-dialog
      v-model="dialogFormToUp"
      title="修改"
      top="5vh"
      @close="resetForm('detailData')"
    >
      <el-scrollbar height="700px">
        <el-form
          ref="detailData"
          :model="detailData"
          label-width="100px"
          class="demo-ruleForm"
          :rules="rules"
        >
          <el-form-item label="项目编号" prop="projectNum">
            <el-input
              v-model="detailData.projectNum"
              disabled
              type="text"
            ></el-input>
          </el-form-item>
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="detailData.projectName" type="text"></el-input>
          </el-form-item>
          <el-form-item label="主持人" prop="hostname">
            <el-input v-model="detailData.hostname" type="text"></el-input>
          </el-form-item>
          <el-form-item label="团队成员" prop="member">
            <el-input v-model="detailData.member" type="text"></el-input>
          </el-form-item>
          <el-form-item label="本人排名" prop="ranking">
            <el-input
              v-model.number="detailData.ranking"
              type="text"
            ></el-input>
          </el-form-item>
          <el-form-item label="主持单位" prop="hostUnit">
            <el-autocomplete
              v-model="detailData.hostUnit"
              :fetch-suggestions="querySearchAsync"
              placeholder="请输入主持单位"
              style="width: 100%"
              @select="handleSelectHostUnit"
              value-key="companyName"
              :trigger-on-focus="false"
            ></el-autocomplete>
          </el-form-item>
          <el-form-item
            label="合作单位"
            prop="cooperationUnit"
            v-show="useable"
          >
            <el-autocomplete
              v-model="detailData.cooperationUnit"
              :fetch-suggestions="querySearchAsync"
              placeholder="请输入主持单位"
              style="width: 100%"
              @select="handleSelectHostUnit"
              value-key="companyName"
              :trigger-on-focus="false"
            ></el-autocomplete>
          </el-form-item>
          <el-form-item label="起始时间" prop="beginDate">
            <el-date-picker
              style="width: 100%"
              v-model="detailData.beginDate"
              type="date"
              placeholder="请选择起始时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="结项时间" prop="endDate">
            <el-date-picker
              style="width: 100%"
              v-model="detailData.endDate"
              type="date"
              placeholder="请选择发表时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="项目级别" prop="level" v-show="useable">
            <el-select
              v-model="detailData.level"
              placeholder="Select"
              style="width: 100%"
            >
              <el-option
                v-for="item in level"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目类别" prop="classification" v-show="useable">
            <el-select
              v-model="detailData.classification"
              placeholder="请选择项目类别"
              style="width: 100%"
            >
              <el-option
                v-for="item in classic"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目总金额" prop="totalPrice">
            <el-input
              v-model.number="detailData.totalPrice"
              type="text"
            ></el-input>
          </el-form-item>
          <el-form-item
            label="财政支持金额"
            prop="financePrice"
            v-show="useable"
          >
            <el-input
              v-model.number="detailData.financePrice"
              type="text"
            ></el-input>
          </el-form-item>
          <el-form-item label="自筹金额" prop="selfPrice" v-show="useable">
            <el-input
              v-model.number="detailData.selfPrice"
              type="text"
            ></el-input>
          </el-form-item>
          <el-form-item label="项目类型" prop="projectType">
            <el-select
              v-model="detailData.projectType"
              placeholder="请选择项目类型"
              style="width: 100%"
              @change="typeChange"
            >
              <el-option
                v-for="item in projectType"
                :key="item.id"
                :label="item.typeName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否结项" prop="endProject">
            <template style="display: flex">
              <el-radio-group v-model="detailData.endProject">
                <el-radio :label="1" style="width: 30%">是</el-radio>
                <el-radio :label="2" style="width: 30%">否</el-radio>
              </el-radio-group>
            </template>
          </el-form-item>

          <el-form-item label="技术指标" prop="specifications">
            <tinymce-editor
              v-if="dialogFormToUp"
              :value="detailData.specifications"
              @input="getInput"
            />
          </el-form-item>

          <el-form-item label="添加附件" prop="file">
            <el-upload
              class="upload-demo"
              :before-remove="beforeRemove"
              :on-change="fileChangeFunc"
              drag
              action=""
              multiple
              name="file"
              style="float: left"
              :file-list="fileList"
              :auto-upload="false"
            >
              <el-icon class="el-icon--upload"><Document /></el-icon>
              <div class="el-upload__text">
                拖放文件上传 或 <em>点击上传</em>
              </div>
              <template #tip>
                <div class="el-upload__tip">
                  单个文件最大为50MB,总上传大小为100MB
                </div>
              </template>
            </el-upload>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm('detailData')"
              >修改</el-button
            >
          </el-form-item>
        </el-form>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script>
import AddProject from "./projectInfoAdd.vue";
import axios from "../../utils/request";
import { ElNotification } from "element-plus";
import { Search, Document } from "@element-plus/icons";
import TinymceEditor from "@/components/TEditor";
import showHtml from "@/components/showHtml";
export default {
  components: { AddProject, Search, Document, TinymceEditor, showHtml },
  inject: ["reload"], //页面刷新函数
  data() {
    return {
      dialogTableVisible: false, //详情弹窗
      dialogFormToUp: false, //修改弹窗
      tableData: [],
      total: "",
      useable: false,
      detailData: {
        classification: "",
        selfPrice: "",
        cooperationUnit: "",
        financePrice: "",
        level: "",
        specifications: "",
      },
      selectFrom: {},
      currentPage: 1,
      pageNum: 1,
      pageSize: 10,
      loading: false,
      fileList: [],
      files: [],
      searchSenior: false,
      showSearch: "",
      // 表单校验规则
      rules: {
        projectNum: [
          { required: true, message: "项目编号不允许为空", trigger: "change" },
        ],
        projectName: [
          { required: true, message: "项目名称不允许为空", trigger: "change" },
        ],
        hostname: [
          { required: true, message: "主持人不允许为空", trigger: "change" },
        ],
        member: [
          { required: true, message: "团队成员不允许为空", trigger: "change" },
        ],
        ranking: [
          { required: true, message: "本人排名不允许为空", trigger: "change" },
          {
            min: 1,
            type: "number",
            message: "请输入大于0的整数",
            trigger: "change",
          },
        ],
        hostUnit: [
          { required: true, message: "主持单位不允许为空", trigger: "change" },
        ],
        beginDate: [
          { required: true, validator: this.checkBeginDate, trigger: "change" },
        ],
        endDate: [
          { required: true, validator: this.checkEndDate, trigger: "change" },
        ],
        totalPrice: [
          {
            required: true,
            message: "项目总金额不允许为空",
            trigger: "change",
          },
          {
            min: 0,
            type: "number",
            message: "请输入大于等于0的数字",
            trigger: "change",
          },
        ],
        projectType: [
          { required: true, message: "项目类型不允许为空", trigger: "change" },
        ],
        cooperationUnit: [
          {
            required: true,
            validator: this.checkCooperationUnit,
            trigger: "blur",
          },
        ],
        level: [
          { required: true, validator: this.checkLevel, trigger: "blur" },
        ],
        classification: [
          {
            required: true,
            validator: this.checkClassification,
            trigger: "blur",
          },
        ],
        financePrice: [
          {
            required: true,
            validator: this.checkFinancePrice,
            trigger: "blur",
          },
          {
            min: 0,
            type: "number",
            message: "请输入大于等于0的数字",
            trigger: "blur",
          },
        ],
        selfPrice: [
          { required: true, validator: this.checkSelfPrice, trigger: "blur" },
          {
            min: 0,
            type: "number",
            message: "请输入大于等于0的数字",
            trigger: "blur",
          },
        ],
        endProject: [
          { required: true, message: "该字段不允许为空", trigger: "change" },
        ],
      },
      restaurants: [],
      state: "",
    };
  },
  methods: {
    searchCollapseShowFun() {
      this.searchSenior = !this.searchSenior;
      if (this.searchSenior) {
        this.showSearch = "search";
      } else {
        this.showSearch = "";
      }
    },
    detailInfo(id) {
      axios
        .get("/ProjectInfo/detail", { params: { id: id } })
        .then((reponse) => {
          if (reponse.data.status === 200) {
            this.dialogTableVisible = true;
            this.detailData = reponse.data.data.projectInfo;
          }
        });
    },
    delectInfo(id) {
      axios
        .get("/ProjectInfo/delete", { params: { id: id } })
        .then((reponse) => {
          if (reponse.data.status === 200) {
            ElNotification({
              message: reponse.data.message,
              type: "success",
            });
            this.getProInfo(this.currentPage);
          }
        });
    },
    updata(id) {
      // console.log(id);
      var self = this;
      self.fileList = [];
      axios({
        method: "get",
        url: "/ProjectInfo/detail",
        params: {
          id: id,
        },
      }).then((reponse) => {
        if (reponse.data.status === 200) {
          self.dialogFormToUp = true;
          self.detailData = reponse.data.data.projectInfo;
          if (reponse.data.data.projectInfo.projectTypeStr === "横向课题") {
            this.useable = false;
          } else {
            this.useable = true;
          }
          for (var i = 0; i < reponse.data.data.projectInfo.files.length; i++) {
            this.fileList.push({
              id: reponse.data.data.projectInfo.files[i].id,
              name: reponse.data.data.projectInfo.files[i].utilSrcName,
              isExcite: true, //服务器中是否存在
            });
          }
        }
      });
    },
    submitForm(val) {
      this.$refs.detailData.validate((valid) => {
        if (valid) {
          var formData = new window.FormData();
          formData.append(
            "projectInfo",
            new Blob([JSON.stringify(this.detailData)], {
              type: "application/json",
            })
          );
          if (this.files.length != 0) {
            this.files.forEach((data) => {
              formData.append("files", data.raw);
            });
          }
          axios.post("/ProjectInfo/upData", formData).then((res) => {
            if (res.data.status === 200) {
              ElNotification({
                message: res.data.message,
                type: "success",
              });
            }
            this.dialogFormToUp = false;
            this.getProInfo(this.currentPage);
          });
        } else {
          return false;
        }
      });
    },
    getLevelInfo() {
      axios.get("/ProjectLevel/ProjectLevelAll").then((reponse) => {
        if (reponse.data.status === 200) {
          this.level = reponse.data.data.projectLevel;
          // console.log(this.level)
        }
      });
    },
    getClassicInfo() {
      axios.get("/ProjectClassic/ProjectClassicAll").then((reponse) => {
        if (reponse.data.status === 200) {
          this.classic = reponse.data.data.projectClassic;
        }
      });
    },
    typeChange(val) {
      if (val === 1) {
        this.useable = true;
      }
      if (val === 2) {
        this.useable = false;
        this.detailData.cooperationUnit = "";
        this.detailData.level = "";
        this.detailData.classification = "";
        this.detailData.financePrice = "";
        this.detailData.selfPrice = "";
      }
    },
    getProjectType() {
      var self = this;
      axios.get("/ProjectType/ProjectTypeAll").then((reponse) => {
        if (reponse.data.status === 200) {
          self.projectType = reponse.data.data.projectType;
        }
      });
    },
    getProInfo(pageNum) {
      this.selectFrom.projectName = this.$route.query.projectName;
      this.loading = true;
      axios({
        method: "post",
        url: "/ProjectInfo/searchInfo/" + pageNum + "/" + this.pageSize,
        data: this.selectFrom,
      }).then((res) => {
        this.tableData = res.data.data.pageInfo.list;
        this.total = res.data.data.pageInfo.total;
        this.loading = false;
        this.selectFrom.projectName = ''
      });
    },
    handleCurrentChange(val) {
      this.getProInfo(this.currentPage);
      this.currentPage = val;
    },
    hasAuth(perm) {
      var authority = this.$store.state.menus.permList;
      return authority.indexOf(perm) > -1;
    },
    // 表单文件上传函数
    beforeRemove(file, fileList) {
      console.log(fileList);
      // var re = this.$confirm(`确定将文件 ${file.name}从服务器中删除?`);
      if (file.isExcite === true) {
        axios
          .get("/UtilFiles/delete", { params: { id: file.id } })
          .then((res) => {
            ElMessage.success("文件" + res.data.message);
          });
      } else {
        this.files.splice(this.files.indexOf(file), 1);
      }
    },
    fileChangeFunc(file, fileList) {
      // console.log("file :",file);
      this.files.push(file);
      console.log("fileList:", fileList);
    },
    getInput(input) {
      this.detailData.specifications = input;
    },
    /**
     * 自定义表单校验规则
     */

    //合作单位
    checkCooperationUnit(rule, value, callback) {
      if (this.detailData.projectType == 1) {
        if (value == "") {
          callback(new Error("合作单位不允许为空"));
        }
      }
      callback();
    },
    //项目级别
    checkLevel(rule, value, callback) {
      if (this.detailData.projectType == 1) {
        if (value == "") {
          callback(new Error("项目级别不允许为空"));
        }
      }
      callback();
    },
    //项目类别
    checkClassification(rule, value, callback) {
      if (this.detailData.projectType == 1) {
        if (value == "") {
          callback(new Error("项目类别不允许为空！"));
        }
      }
      callback();
    },
    //财政支持金额
    checkFinancePrice(rule, value, callback) {
      if (this.detailData.projectType == 1) {
        if (value == "") {
          callback(new Error("财政支持金额不允许为空"));
        } else if (
          value >
          this.detailData.totalPrice - this.detailData.selfPrice
        ) {
          callback(new Error("不得大于项目总金额"));
        }
      }
      callback();
    },
    //自筹金额
    checkSelfPrice(rule, value, callback) {
      if (this.detailData.projectType == 1) {
        if (value == "") {
          callback(new Error("自筹金额不允许为空！"));
        } else if (
          value >
          this.detailData.totalPrice - this.detailData.financePrice
        ) {
          callback(new Error("不得大于项目总金额"));
        }
      }
      callback();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //起始日期
    checkBeginDate(rule, value, callback) {
      let beginDate = new Date(value);
      let nowDate = new Date();

      if (beginDate > nowDate) {
        callback(new Error("起始时间不允许大于当前时间"));
      } else {
        callback();
      }
    },
    checkEndDate(rule, value, callback) {
      let endDate = new Date(value);
      let nowDate = new Date();
      let beginDate = new Date(this.detailData.beginDate);
      if (endDate < beginDate) {
        callback(new Error("结项时间不能小于起始时间"));
      } else if (endDate > nowDate) {
        callback(new Error("结项时间不能大于当前时间"));
      } else {
        callback();
      }
    },

    /**
     * 单位信息输入建议
     */
    //获取单位信息
    getCompanyInfo() {
      axios.get("/CompanyInfos/searchInput").then((res) => {
        // console.log(res);
        this.restaurants = res.data.data.map_companyInfo;
      });
    },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;
      cb(results);
    },
    createStateFilter(queryString) {
      return (state) => {
        return (
          state.companyName.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    handleSelectHostUnit(item) {
      this.detailData.hostUnitId = item.id;
    },
    handleSelectCooperation(item) {
      this.detailData.cooperationUnitId = item.id;
    }

  },
  mounted() {
    //数据获取 —— 项目
    this.getProInfo(this.pageNum);
    //项目级别数据获取
    this.getLevelInfo();
    this.getClassicInfo();
    this.getProjectType();
    this.getCompanyInfo();
  },
  computed: {
    token: {
      get() {
        return localStorage.getItem("token");
      },
    },
  },
};
</script>


<style scoped>
.searchHead {
  background-color: slategrey;
}
</style>
